package com.gaogzhen.datastructure.graph.maintest;

import edu.princeton.cs.algs4.*;

import java.io.File;

/**
 * 测试最小生成树
 * @author gaogzhen
 */
public class TestMst {

    public static void main(String[] args) {
        // testLazyPrim();
        // testPrim();
        testKruskal();
    }

    public static void testKruskal() {
        String path = System.getProperty("user.dir") + File.separator + "asserts/tinyEWG.txt";
        In in = new In(path);
        EdgeWeightedGraph G = new EdgeWeightedGraph(in);
        KruskalMST mst = new KruskalMST(G);
        for (Edge e : mst.edges()) {
            StdOut.println(e);
        }
        StdOut.printf("%.5f\n", mst.weight());
    }

    public static void testPrim() {
        String path = System.getProperty("user.dir") + File.separator + "asserts/tinyEWG.txt";
        In in = new In(path);
        EdgeWeightedGraph G = new EdgeWeightedGraph(in);
        PrimMST mst = new PrimMST(G);
        for (Edge e : mst.edges()) {
            StdOut.println(e);
        }
        StdOut.printf("%.5f\n", mst.weight());
    }


    public static void testLazyPrim() {
        String path = System.getProperty("user.dir") + File.separator + "asserts/tinyEWG.txt";
        In in = new In(path);
        EdgeWeightedGraph G = new EdgeWeightedGraph(in);
        LazyPrimMST mst = new LazyPrimMST(G);
        for (Edge e : mst.edges()) {
            StdOut.println(e);
        }
        StdOut.printf("%.5f\n", mst.weight());
    }
}
